package madixin.t128;

import java.util.HashSet;
import java.util.Set;

class Solution {
    public int longestConsecutive(int[] nums) {
        int longest = 0;
        Set<Integer> index = new HashSet<>();
        for (int n : nums) {
            index.add(n);
        }

        for (int n : nums) {
            int cur = n + 1;
            int length = 1;
            while (index.contains(cur)) {
                length++;
                cur++;
            }
            longest = Math.max(length, longest);
        }
        return longest;
    }

    public static void main(String[] args) {
        Solution s = new Solution();

        System.out.println(s.longestConsecutive(new int[]{100, 4, 200, 1, 3, 2}));
    }

}